package me.riverslob.test.esper.http;

import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import com.espertech.esper.client.scopetest.SupportUpdateListener;
import com.espertech.esperio.http.EsperIOHTTPAdapterPlugin;
import me.riverslob.test.esper.ExampleMain;

import java.util.Properties;

/**
 * <br/>Created on 13-9-12 上午9:48
 *
 * @author 郑治明（zm.zheng@zhuche.com）
 * @since 3.1.11
 */
public class InputPutSampleMain {
    public static void main(String[] args) throws InterruptedException {
//        SupportUpdateListener listener = new SupportUpdateListener();
        int port = 8082;
        String engineURI = "TestHTTPAdapterOutputClassic";

        String esperIOHTTPConfig = "<esperio-http-configuration>\n" +
                "<service name=\"service1\" port=\"" + port + "\" nio=\"" + false + "\"/>" +
                "<get service=\"service1\" pattern=\"*\"/>" +
                "</esperio-http-configuration>";

        Configuration engineConfig = new Configuration();
        engineConfig.addPluginLoader("EsperIOHTTPAdapter", EsperIOHTTPAdapterPlugin.class.getName(), new Properties(), esperIOHTTPConfig);

        engineConfig.addEventType("SupportBean", SupportBeanTemp.class);
        engineConfig.addEventType("SupportBeanTwo", SupportBeanTwo.class);

        EPServiceProvider provider = EPServiceProviderManager.getProvider(engineURI, engineConfig);

        EPStatement stmt = provider.getEPAdministrator().createEPL("select * from SupportBean");
//        stmt.addListener(listener);
        stmt.addListener(new ExampleMain.CEPListener());

//        System.out.println(listener.assertOneGetNew());

        Thread.sleep(1000*60*3);

        provider.destroy();
    }
}
